package gdconf

import (
	"server_cluster/common/logger"
)

// 战斗技能卡配置表

type BattleSkillCardConfig struct {
	CardId            int32    `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 技能卡id
	Weight            int32    `csv:"Weight,omitempty"`
	CardTarget        int32    `csv:"Cardtarget,omitempty"`
	SubSkill123CdTime IntArray `csv:"CardColdTime,omitempty"` // 子技能123冷却时间数组
	SubSkill1IdSeq    IntArray `csv:"Skilllevel1,omitempty"`  // 子技能1id序列
	SubSkill2IdSeq    IntArray `csv:"Skilllevel2,omitempty"`  // 子技能2id序列
	SubSkill3IdSeq    IntArray `csv:"Skilllevel3,omitempty"`  // 子技能3id序列
}

func (bsk *BattleSkillCardConfig) TableName() string {
	return "config_battle_skill_card_logic"
}

func (g *GameDataConfig) saveBattleSkillCardConfig() {
	saveTableToDb[BattleSkillCardConfig](g.Db, readTable[BattleSkillCardConfig](g.CsvPathPrefix+"BattleSkillCard.csv"))
}

func (g *GameDataConfig) loadBattleSkillCardConfig() {
	g.GameDataMaps.BattleSkillCardConfigMap = make(map[int32]*BattleSkillCardConfig)
	for _, battleSkillCardConfig := range loadTableFromDb[BattleSkillCardConfig](g.Db) {
		g.GameDataMaps.BattleSkillCardConfigMap[battleSkillCardConfig.CardId] = battleSkillCardConfig
	}
	logger.Info("BattleSkillCardConfig Count: %v", len(g.GameDataMaps.BattleSkillCardConfigMap))
}

func GetBattleSkillCardConfig(cardId int32) *BattleSkillCardConfig {
	value, exist := CONF.GameDataMaps.BattleSkillCardConfigMap[cardId]
	if !exist {
		logger.Error("[ConfigNotFound] BattleSkillCardConfig, cardId: %v", cardId)
		return nil
	}
	return value
}

func GetBattleSkillCardConfigMap() map[int32]*BattleSkillCardConfig {
	return CONF.GameDataMaps.BattleSkillCardConfigMap
}
